package com.itjeffrey.autocode.service;

import com.itjeffrey.autocode.bo.RandomWordBO;
import com.itjeffrey.autocode.runner.RandomWordInitRunner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Slf4j
@Component
public class ACListener implements ApplicationListener<RandomWordBO> {

    @Autowired
    private RandomWordInitRunner randomWordInitRunner;

    @Override
    public void onApplicationEvent(RandomWordBO randomWordBO) {
        if (Objects.nonNull(randomWordBO)) {
            randomWordInitRunner.setRandomWordBO(randomWordBO);
        }
    }
}
